void UpdateFromNumberThreadsSliderChange()
{
    DWORD dwThreads = g_UI.GetSlider(IDC_SLIDER)->GetValue();
    if(g_bAutoTesting )
        dwThreads = g_TestThreads;
    WCHAR wszOutput[1024];
    if(dwThreads != g_dwNumberofRecordThreads && g_bMultiThread)
    {
        DestroyThreads();
        //DestroyGeometry();
        g_bMultiThread = true;
        g_dwNumberofRecordThreads_toBeSet = dwThreads;
    }
    StringCchPrintf( wszOutput, 1024, L"Number of Worker Threads: %d",
                dwThreads );
    g_UI.GetStatic( IDC_LABEL )->SetText( wszOutput );
    int NumberDPs = CalculateDPs( );
     StringCchPrintf( wszOutput, 1024, L"Number of DrawPrimitives: %d",  NumberDPs );
    g_UI.GetStatic( IDC_LABELDP )->SetText( wszOutput );
}

void UpdateFromNumberDPsSliderChange()
{
    DWORD dwObjectsSQRT = g_UI.GetSlider(IDC_SLIDERDP)->GetValue();
    WCHAR wszOutput[1024];
    bool bMultiThread = g_bMultiThread;
    DWORD dwThreads = g_dwNumberofRecordThreads;
    if(dwObjectsSQRT != g_dwNumberofObjectsSqrt)
    {
        g_dwNumberofObjectsSqrt = dwObjectsSQRT;
        DestroyThreads();
        g_bMultiThread = bMultiThread;
        g_dwNumberofRecordThreads_toBeSet = dwThreads;
    }
    StringCchPrintf( wszOutput, 1024, L"Number of Worker Threads: %d",
                dwThreads );
    g_UI.GetStatic( IDC_LABEL )->SetText( wszOutput );
    int NumberDPs = CalculateDPs( ); 
    StringCchPrintf( wszOutput, 1024, L"Number of DrawPrimitives: %d",  NumberDPs );
    g_UI.GetStatic( IDC_LABELDP )->SetText( wszOutput );
}

void UpdateFromThreadingChange()
{
    WCHAR wszOutput[1024];
    g_bMultiThread = !g_bMultiThread; 
    bool bMultiThread = g_bMultiThread;
    DWORD dwThreads = g_dwNumberofRecordThreads;
    g_UI.GetControl( IDC_LABEL )->SetVisible(g_bMultiThread);
    g_UI.GetControl( IDC_SLIDER )->SetVisible(g_bMultiThread);
    DestroyThreads();
    g_bMultiThread = bMultiThread;
    int NumberDPs = CalculateDPs( );
    ((CDXUTSlider*)g_UI.GetControl( IDC_SLIDERDP ))->SetValue( g_dwNumberofObjectsSqrt );
    StringCchPrintf( wszOutput, 1024, L"Number of DrawPrimitives: %d",  NumberDPs );
    g_UI.GetStatic( IDC_LABELDP )->SetText( wszOutput );
    ((CDXUTSlider*)g_UI.GetControl( IDC_SLIDER ))->SetValue( g_dwNumberofRecordThreads );
    StringCchPrintf( wszOutput, 1024, L"Number of Worker Threads: %d", g_dwNumberofRecordThreads );
    g_UI.GetStatic( IDC_LABEL )->SetText( wszOutput );

}

void UpdateFromControls()
{
    if(g_bUpdateThreading)
    {
#if DOTRACE
        char temp[300];
        sprintf_s(temp,299,"UpdateFromControls UpdateThreading.\n");
        OutputDebugStringA(temp);
#endif
        UpdateFromThreadingChange();
    }
    g_bUpdateThreading = false;
    if(g_bUpdateThreadCount)
    {
#if DOTRACE
        char temp[300];
        sprintf_s(temp,299,"UpdateFromControls UpdateThreadCount.\n");
        OutputDebugStringA(temp);
#endif
        UpdateFromNumberThreadsSliderChange();
    }
    g_bUpdateThreadCount = false;
    if(g_bUpdateDPs)
    {
#if DOTRACE
        char temp[300];
        sprintf_s(temp,299,"UpdateFromControls UpdateDPs.\n");
        OutputDebugStringA(temp);
#endif
        UpdateFromNumberDPsSliderChange();
    }
    g_bUpdateDPs = false;

    // Update the thread count
    g_dwNumberofRecordThreads = g_dwNumberofRecordThreads_toBeSet;
    if(g_bAutoTesting )
        g_bMultiThread = g_dwNumberofRecordThreads > 0;
}
